package icbc.nav.view
{
	import flash.display.Sprite;
	import flash.filters.BevelFilter;
	import flash.filters.DropShadowFilter;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import icbc.app.AppGlobal;
	import icbc.app.util.GlideTransition;
	import icbc.nav.event.ViewEvent;
	
	public class View extends Sprite
	{
		protected var panel:Sprite;
		public var viewWidth:uint;
		public var viewHeight:uint;
		private var _needReadyStatus:Boolean = false;
		public function get needReadyStatus():Boolean { return _needReadyStatus; }
		public function set needReadyStatus(value:Boolean):void
		{
			if(value) visible = false;
			_needReadyStatus = value;
		}

		public function View()
		{
			super();
		}

		protected function setBasePanel():Sprite
		{
			viewWidth = AppGlobal.DEFAULT_WIDTH;
			viewHeight = AppGlobal.DEFAULT_HEIGHT;
			return buildPlainPanel();
		}
		
		protected function buildPlainPanel():Sprite
		{
			var base:Sprite = new Sprite();
			var rounded:uint = 5;
			base.graphics.beginFill(0xE6E8D8,0);
			base.graphics.drawRoundRect(0, 0, viewWidth, viewHeight, rounded, rounded);
			base.graphics.endFill();
			return base;
		}

		protected function centerSprite(sprite:Sprite):void
		{
			sprite.x = stage.stageWidth/2 - sprite.width/2;
			sprite.y = stage.stageHeight/2 - sprite.height/2;
		}

		protected function buildText(config:Object):TextField
		{
			var text:String = (config.text != undefined)?config.text:"";
			var width:uint = (config.width != undefined)?config.width:120;
			var height:uint = (config.height != undefined)?config.height:18;
			var color:uint = (config.color != undefined)?config.color:0xffffff;
			var size:uint = (config.size != undefined)?config.size:30;
			var align:String = (config.align != undefined)?config.align:"center";
			var wordWrap:Boolean = (config.wordWrap != undefined)?config.wordWrap:false;
			var border:Boolean = (config.border != undefined)?config.border:false;
			var bold:Boolean = (config.bold != undefined)?config.bold:false;
			var format:TextFormat = new TextFormat();
			format.font = AppGlobal.FONT_NAME;
			format.color = color;
			format.size = size;
			format.align = align;
			format.bold = bold;
			var txt:TextField = new TextField();
			txt.selectable = false;
			txt.width = width;
			txt.height = height;
			txt.defaultTextFormat = format;
			txt.text = text;
			txt.wordWrap = wordWrap;
			txt.border = border;
			return txt;
		}

		protected function doTransition(prevView:View, nextView:View):void
		{
			if(!prevView)
			{
				if(nextView.needReadyStatus)
					nextView.visible = true;
				return;
			};
			var onComplete:Function = function():void{ nextView.initView(); };
			if(nextView.needReadyStatus)
			{
				var readyFnc:Function;
				nextView.addEventListener(ViewEvent.READY, readyFnc = function(evt:ViewEvent):void{
					nextView.removeEventListener(ViewEvent.READY, readyFnc);
					GlideTransition.start(prevView,nextView,true, onComplete);
				});
			} else {
				GlideTransition.start(prevView,nextView,true, onComplete);
			}
		}

		public function initView():void
		{
		}
	}
}